home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / mac / General Interest / KeyQuencer 1.2.1 / Developer’s toolkit / Extension code / Action.h < prev    next >
Text File  |  1994-11-23  |  3KB  |  61 lines

  1. // =============================================================================
  2. // KEYQUENCER EXTENSIONS SAMPLE PROJECT HEADER - VERSION 1.2.1 - NOVEMBER 1994
  3. // ⌐1994 Alessandro Levi Montalcini <LMontalcini@pmn.it>
  4. // Don╒t forget to send me any cool extensions you create!
  5. // This text looks best in monaco 9 font, 4 spaces per tab, no wrapping
  6.  
  7. #ifndef _H_action
  8. #define _H_action
  9.  
  10. // =============================================================================
  11. // The Extension.c file provides a simple way to set up your globals
  12. // and dispatch the extension messages. You don't have to call SetUpA4() or
  13. // RestoreA4() in the init() and run() routines because the main() routine in
  14. // the Extension.c file has done all the dirty work for you.
  15. // You can use the Extension.c file without modifications and add your own
  16. // code to the Action.c file, inside the existing init() and run() routines.
  17. // =============================================================================
  18. // PROTOTYPES:
  19.  
  20. short    run        (ParamsPtr params, MachineHandle mac, GluePtr glue);
  21. short    init    (MachineHandle mac, GluePtr glue);
  22.  
  23. long    SetupExtensionWorld        (void);
  24. void    RestoreExtensionWorld    (long world);
  25.  
  26. // =============================================================================
  27. // The SetupExtensionWorld and RestoreExtensionWorld are needed if you
  28. // install patches or callbacks that may be called by the system and still
  29. // want to access your extension globals. Here's an example of how to do it:
  30. /*
  31.  
  32. long gOldTrapAddress;                        // this is a global variable (the original trap address)
  33.  
  34. short init(MachineHandle mac, GluePtr glue)    // this is your extension's init() routine
  35. {
  36.     gOldTrapAddress = (long)GetToolTrapAddress(_TheTrapToPatch);
  37.     SetToolTrapAddress((UniversalProcPtr)MyTrapPatch, _TheTrapToPatch);
  38.     return kExtNoError;
  39. }
  40.  
  41. pascal void MyTrapPatch(void)                // this is your trap patch
  42. {                                            // (usually declared as pascal for toolbox traps)
  43.     pascal void (*OriginalTrap)(void);    
  44.     long world;
  45.     
  46.     world = SetupExtensionWorld();            // get access to your extension's globals
  47.     
  48.     // you may use your globals here
  49.     
  50.     OriginalTrap = (void*)gOldTrapAddress;    // gOldTrapAddress won't be available after RestoreExtensionWorld()
  51.     RestoreExtensionWorld(world);            // but the local variable will be OK
  52.     (*OriginalTrap)();                        // this is both a head and a tail patch, which is a Bad Thing
  53. }                                            // (you have to use some assembler to avoid it)
  54.  
  55. */
  56. // =============================================================================
  57.  
  58. #endif // _H_action
  59.  
  60. // =============================================================================
  61.